#!/usr/bin/env python
#coding=utf-8

from flask import session, request, redirect, url_for

from aladin.helpers import toint

from app import views
from app.views import admin


# 项目app名称
DEFAULT_APP_NAME = 'app'

# modules
DEFAULT_MODULES = (
    (views.index,           ''),
    (views.user,            '/user'),
    (views.teacher,         '/teacher'),

    (admin.admin_index,     '/admin'),
    (admin.sys,             '/admin/sys'),

    
)

def configure_before_handlers(app):

    @app.before_request
    def authenticate():

        # 排除校验的endpoint和static
        endpoint = request.endpoint
        if (endpoint in ('index.welcome', 'index.signin', 'index.signout') 
                    or request.path.find('/static') == 0):
            return

        admin_id = toint(session.get('admin_id', '0'))
        if admin_id <= 0:
            return redirect(url_for('index.signin'))

